// 导入 api
import { findAllCategory } from '@/api/category'
// 导入 默认的数据
import { topCategory } from '@/api/constants'
export default {
  // 开启了命名空间
  namespaced: true,
  state: {
    // 默认的分类列表
    cateList: topCategory.map(v => {
      return {
        name: v
      }
    })
  },
  mutations: {
    setCateList (state, newCateList) {
      state.cateList = newCateList
    }
  },
  actions: {
    async getCateList (context) {
      const res = await findAllCategory()
      // console.log('res:', res)
      context.commit('setCateList', res.result)
    }
  }
}
